package myjdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @Auther: cty
 * @Date: 2020/1/21 18:50
 * @Description:  测试使用JDBCUtil工具类来简化开发
 * @version: 1.0
 */
public class JDBC_Demo09_Util {
    public static void main(String[] args) {
        Connection conn = null;
        PreparedStatement ps = null;

        try {
            //1 加载数据库驱动  2 获取数据库连接
            conn = JDBCUtil.getMysqlConn();
            //3 操作数据库
            String sql = "insert into user (username) value(?)";
            ps = conn.prepareStatement(sql);
            ps.setObject(1,"cty");
            ps.executeUpdate();
            System.out.println("存入一条记录！");
            //4 处理返回数据

        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            //5 关闭连接
            JDBCUtil.close(ps,conn);
        }
    }
}

/* res:
存入一条记录！
*/